/*
 * Contains the graphical objects, dependent on Raphael.js
 * It's not really testable
 */

if(!mindgraph) {
    var mindgraph = {};
}
mindgraph.origami = {};
mindgraph.origami.paper = undefined;

mindgraph.origami.init = function () {
    mindgraph.log("Origami init");
    var scroll = document.getElementById("scroll");
    mindgraph.origami.paper = Raphael(scroll, 1200, 1200);
    var firstRect = mindgraph.origami.paper.rect(20, 20, 50, 50, 5).attr({stroke: "red"});
    if(scroll) {
        mindgraph.log("Registering onclick");
        scroll.addEventListener('click', mindgraph.origami.paperOnClick, true);
    }
}

mindgraph.origami.Model = {
    create: function (setup) {
        var result = undefined;
        var type = setup && setup.type;
        if(type) {
            if(type === mindgraph.theory.types.node) {
                result = paper.rect(setup.x, setup.y);
            } else if(type === mindgraph.theory.types.edge) {
                result = paper.path();
            }
        }
        return result;
    }
}

mindgraph.origami.paperOnClick = function(event) {
    mindgraph.log("onclick");
    if(event) {
        var x = event.clientX;
        var y = event.clientY;
        paper.rect(x, y, 50, 4);
    }
}